<?php


namespace app\middleware;

use app\service\exception\ApiException;
use app\service\exception\BaseException;
use app\service\model\ConfigModel;

class SiteAuth
{
    /**
     * 接口访问权限验证
     * @param $request
     * @param \Closure $next
     * @return mixed
     * @throws BaseException
     */
    public function handle($request, \Closure $next)
    {
        // 检查站点是否关闭
        $config = ConfigModel::getConfigValue('site_status');
        if (!($config['value'] ?? 0)) {
            throw new BaseException(['msg' => $config['remark'] ?? '暂停营业中', 'errorCode' => 999]);
        }

        return $next($request);
    }
}